<?php

require_once("includes/database.php"); 


if (!empty($_POST['email']))
if (!empty($_POST['firstname']))
if (!empty($_POST['lastname']))
if (!empty($_POST['contact_no']))
if (!empty($_POST['password']))
if (!empty($_POST['pet_type']))
if (!empty($_POST['pet_gender']))
if (!empty($_POST['pet_name']))
if (!empty($_POST['pet_breed']))
if (!empty($_POST['pet_bday']))
{	
$email = $_POST['email'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$contact_no = $_POST['contact_no'];
$password = $_POST['password'];
$pet_type = $_POST['pet_type'];
$pet_gender = $_POST['pet_gender'];
$pet_name = $_POST['pet_name'];
$pet_breed = $_POST['pet_breed'];
$pet_bday = $_POST['pet_bday'];
$unique_user = uniqid();
$unique_pet = mt_rand();
date_default_timezone_set ("Asia/Hong_Kong");
$timezone= date_default_timezone_get();

$date =date("Y/m/d");

$tsql="INSERT INTO user_db(User_ID,Joined,User_Level,Email_Address,First_Name,Last_Name,Contact_Number,Password) 
Values('{$unique_user}','{$date}','3','{$email}','{$firstname}','{$lastname}','{$contact_no}','{$password}')";

mysql_query($tsql);

$clientId = mysql_insert_id(); 

$tsql="INSERT INTO pet_info_db(Pet_Type,Pet_Gender,Pet_Name,Pet_Breed,Pet_Birthday,Pet_Owner,Owner_User_ID,Pet_ID) 
Values('{$pet_type}','{$pet_gender}','{$pet_name}','{$pet_breed}','{$pet_bday}','{$firstname} {$lastname}','{$unique_user}','{$unique_pet}')";

mysql_query($tsql);

$clientId = mysql_insert_id(); 

$tsql="INSERT INTO pet_info_null_db(Pet_Type,Pet_Gender,Pet_Name,Pet_Breed,Pet_Birthday,Pet_Owner,Owner_User_ID,Pet_ID) 
Values('{$pet_type}','{$pet_gender}','{$pet_name}','{$pet_breed}','{$pet_bday}','{$firstname} {$lastname}','{$unique_user}','{$unique_pet}')";

mysql_query($tsql);

$clientId = mysql_insert_id(); 

$tsql="INSERT INTO vaccine_db(Owner_User_ID,Owner_Name,Pet_ID)
Values('{$unique_user}','{$firstname} {$lastname}','{$unique_pet}')";







$data =  mysql_query($tsql,$con);

if( $data )
{
     /*echo "Connection established.\n";*/
	 $message = "Registration Successful!";
	 echo "<script type='text/javascript'>alert('$message');window.location = 'thesis_login_register.php';</script>";
}
else
{
    $message = "Registration Failed. Check information.!";
	 echo "<script type='text/javascript'>alert('$message');window.location = 'thesis_login_register.php';</script>";
     die( print_r( mysql_error(), true));
}
}

?>